package com.lzj;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;

import java.util.HashSet;
import java.util.Set;

public class App {
    public static void main(String[] args) {
        //创建jedisCluster对象，有一个参数 nodes是Set类型，Set包含若干个HostAndPort对象
        Set<HostAndPort> nodes = new HashSet<>();
        nodes.add(new HostAndPort("192.168.91.129", 7001));
        nodes.add(new HostAndPort("192.168.91.129", 7002));
        nodes.add(new HostAndPort("192.168.91.129", 7003));
        nodes.add(new HostAndPort("192.168.91.129", 7004));
        nodes.add(new HostAndPort("192.168.91.129", 7005));
        nodes.add(new HostAndPort("192.168.91.129", 7006));
        nodes.add(new HostAndPort("192.168.91.129", 7007));
        nodes.add(new HostAndPort("192.168.91.129", 7008));
        JedisCluster jedisCluster = new JedisCluster(nodes);
        //使用jedisCluster操作redis
        jedisCluster.set("lg:k1", "v1");
        String str = jedisCluster.get("lg:k1");
        System.out.println(str);
        //关闭连接池
        jedisCluster.close();

    }
}
